﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MVC3AsyncFileUploadDemo
{
	/// <summary>
	/// Represents the wrapped json result
	/// </summary>
	public class WrappedJsonResult : JsonResult
	{
		/// <summary>
		/// Enables processing of the result of an action method by a custom type that
		/// inherits from the System.Web.Mvc.ActionResult class. Method is overriden for custom use.
		/// </summary>
		/// <param name="context">The context within which the result is executed.</param>
		public override void ExecuteResult(ControllerContext context)
		{
			// we are writing down the HTML template
			context.HttpContext.Response.Write("<html><body><textarea id=\"jsonResult\" name=\"jsonResult\">");

			// we are writing the JsonResult.Data inside the textarea html control
			// JsonResult.Data is of Annonymous type.
			base.ExecuteResult(context);

			// we have written inside the textarea so we can close it
			context.HttpContext.Response.Write("</textarea></body></html>");

			// set the content type as text/html
			context.HttpContext.Response.ContentType = "text/html";
		}
	}
}